# -*- coding: utf-8 -*-

"""
Module Description:
Date: 2020/5/19
Author: HuYuanCheng
"""
from pyshare.utils.time_utils import getCT, has_pass_time, get_another_time
from pyshare.dal.gameconfig.game_env import get_config_env_set
from pyshare.const.enums.activity import ActivityStatus, GrowthPlanStatus


class NewGrowthPlanActivityMixin(object):
    __slots__ = ()
    start_time = NotImplemented
    end_time = NotImplemented
    activity_status = NotImplemented

    @property
    def is_time_open(self):
        # 活动时间是否有效
        return self.start_time <= getCT() < self.end_time

    @property
    def is_time_not_start(self):
        # 活动时间是否未开始
        return getCT() < self.start_time

    @property
    def is_expire(self):
        # 活动是否过期
        return self.end_time <= getCT()

    @property
    def is_expire_clear(self):
        # 是否到了活动记录删除状态
        return has_pass_time(self.end_time, days=get_config_env_set('ActivityExpireClearTime'))

    @property
    def is_send(self):
        # 是否可发送奖励
        return self.activity_status == GrowthPlanStatus.Opening


class RoleNewGrowthPlanMixin(object):
    __slots__ = ()
    create_time = NotImplemented
    end_time = NotImplemented
    plan_type = NotImplemented
    plan_id = NotImplemented
    plan_version = NotImplemented

    @property
    def days(self):
        # 当前为购买后的第几天
        if self.plan_type and self.plan_id and self.plan_version:
            return (getCT().replace(hour=0, minute=0, second=0) - self.create_time.replace(
                hour=0, minute=0, second=0, microsecond=0)).days
        else:
            return 0

    @property
    def is_time_open(self):
        # 活动时间是否有效
        return self.create_time <= getCT() < self.end_time

    @property
    def is_time_not_start(self):
        # 活动时间是否未开始
        return getCT() < self.create_time

    @property
    def is_expire(self):
        # 活动是否过期
        return self.end_time <= getCT()

    @property
    def is_expire_clear(self):
        # 是否到了活动记录删除状态
        return has_pass_time(self.end_time, days=get_config_env_set('ActivityExpireClearTime'))

    @property
    def send_time(self):
        # 定时任务发奖时间
        return get_another_time(self.end_time, seconds=30)

    @property
    def is_purchased(self):
        # 是否购买
        if self.plan_type and self.plan_id and self.plan_version:
            return True
        else:
            return False

